package com.lcxw.hxzbadmin.controller.membercontroller;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.lcxw.hxzbapi.entity.pojo.AddCoin;
import com.lcxw.hxzbapi.service.AddCoinService;
import com.lcxw.hxzbapi.service.YwpdMemberService;
import com.lcxw.hxzbcommon.common.StringUtil;

@Component
public class MemberCoinRealization {

    @Resource
    YwpdMemberService ywpdMemberService;

    @Resource
    AddCoinService addCoinService;

    //1、操作加值
    public void addCoin(long userId, int coin) throws Exception {
        ywpdMemberService.updateCoinByUserId(coin, userId);
    }

    //2、记录加值记录
    public void addCoinDetail(long userId, int coin, String adminName, String ip)
        throws Exception {
        AddCoin addCoin = new AddCoin();
        addCoin.setUserId(userId);
        addCoin.setAddCoin(coin);
        addCoin.setAddTime(StringUtil.getDateTime());
        addCoin.setAdminName(adminName);
        addCoin.setIp(ip);
        addCoinService.insert(addCoin);
    }

    //3、动态获取加值记录的条数
    public int getSumDetailsDync(Long userId, String startTime, String endTime,
        String adminName) {

        return addCoinService.selectSumAddCoinDync(userId, startTime, endTime, adminName);
    }

    //4、动态获取加值记录
    public List<AddCoin> getDetailDync(Long userId, String startTime, String endTime,
        String adminName, int pageIndex, int pageSize) {
        pageIndex = (pageIndex - 1) * pageSize;
        return addCoinService
            .selectAddCoinDync(userId, startTime, endTime, adminName, pageIndex, pageSize);
    }

}
